#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using ll = long long;
using namespace std;

bool check(ll i, vector<ll>& nums, ll k) {
    ll res = 0;
    for (auto x : nums) res += min(x, i);
    return res / k >= i;
}

ll solve(vector<ll>& nums, ll k) {
    ll left = 1, right = accumulate(nums.begin(), nums.end(), 0LL) / k, mid;
    while (left <= right) {
        mid = left + ((right - left) >> 1);
        if (check(mid, nums, k)) left = mid + 1;
        else right = mid - 1;
    }
    return left - 1;
}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    cout << solve(arr, k) << endl;
    return 0;
}